﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChoiceUserInfo.aspx.cs" Inherits="SysManage_ChoiceUserInfo" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>用户信息选择</title>
    <link rel="stylesheet" href = "SysManage.CSS" type="text/css" />
    <script language ="javascript" type="text/javascript" >
    <!--
function ck(obj,obj1)
{
    if(obj.lowsrc=="") return true;
    obj.imgRolln=obj.src;
    obj.src=obj.lowsrc;
    obj.lowsrc=obj.imgRolln;
    if(obj1.style.display=='none')
       obj1.style.display='';
    else
       obj1.style.display='none';
}

var GOrgInfo = "" ;
var GNextOrgID = "";      //本级及下级部门ID集合
var GNoRepeatOrgID = "";  //得到本级及下级不重复部门ID集合
var GPersCount = "0";     //当前树中所关联到的人员数;
var GOrgCount = "0";      //当前树中所关联到的组织数;
//显示树型
function show_tree(space_c,ParentID)
{
  var i,j,k,img_src1,img_src2; 
  for(k=0;k<trees.length;k++)
  {
    if(trees[k].ParentID == ParentID)
    {      
      document.write("<table border=0 cellspacing=0 cellpadding=0 bordercolor=#000000 width=100%><tr><td>");      
      for(i=1;i<=space_c;i++)
        document.write("&nbsp;&nbsp;");
      if(GOrgInfo!="")
      {
        if(trees[k].ID != ParentID)
        {
           img_src1="img/sys/close.gif";
           img_src2="img/sys/open.gif";
        } 
        var ary  = GOrgInfo.split(',');
        var nary = ary.length;
        for(i=0;i<nary-1;i++)
        {
          if(trees[k].ID == ary[i])
          {
            img_src1="img/sys/open.gif";
            img_src2="img/sys/close.gif";
          }
          if(trees[k].ParentID == ary[i])
          {
             img_src1="img/sys/close.gif";
             img_src2="img/sys/open.gif";
           }             
        }        
      }
      else
      {
           img_src1="img/sys/close.gif";           
           img_src2="img/sys/open.gif";           
      }      
      if(trees[k].ChildNumber=="0" && trees[k].PersNumber=="0")
      {
        img_src1="img/sys/open.gif";
        img_src2="img/sys/open.gif";
      }
      document.write("<img lowsrc=" + img_src2 + " id=\"img_"+trees[k].ID+"\" onclick=\"ck(this,document.all.T" + trees[k].ID + ");\" src=" + img_src1 + " align=middle>&nbsp;<label id=\"Lable1\"  style=\"cursor:pointer\" onclick=\"tog(this,'#ffffff');var sTemp = '"+trees[k].ID+"'; SpreadNextOrgTree(sTemp,'" + trees[k].ChildNumber + "','" + trees[k].PersNumber + "'); \" >" + trees[k].Name + "</label>");

      if(trees[k].ChildNumber=="0" && trees[k].PersNumber=="0")
      {
          document.write ("</td></tr></table>" );  
      }
      else
      {
          document.write ("&nbsp;&nbsp;<input type=\"checkbox\" name=\"DeptCK\" onclick=\"ClearItem();GetNextOrgID("+trees[k].ID+");DelRepeatData(GNextOrgID);IFChoice(this);\" value=\"" + trees[k].ID + "\" /></td></tr></table>" );
      }      
      document.write ("<span id='T" + trees[k].ID + "' style='display:none'>" );      
      var x;
      for(x=0;x<Perstrees.length;x++)
       {
         if(Perstrees[x].OrgID == trees[k].ID)
         {
           GPersCount = GPersCount*1+1
           for(i=0;i<=space_c;i++)
             document.write("&nbsp;&nbsp;");
           document.write("<img id=\"ImgPers\" src=\"img/sys/personal.gif\" width=\"16\">&nbsp;&nbsp;"+Perstrees[x].Name+"&nbsp;&nbsp;<input type=\"checkbox\" id=\"PersCK\" name=\"PersCK\" value=\"" + Perstrees[x].ID + "," + Perstrees[x].Name + ","+ Perstrees[x].OrgID +  "\" /><br>");
          }
       }
      if(trees[k].ChildNumber != "0")
      {
        show_tree(space_c +1 ,trees[k].ID);
       }
      document.write ("</span>");
    }
  }
}


function ClearItem()
{
    GNextOrgID = "";    
    sGetPersIDCol="";
}

function GetNextOrgID(OrgID)   //取得同级及下级部门ID的集合.为选择人员做准备
{
  var k;
  GNextOrgID = GNextOrgID + OrgID+",";
  for(k=0;k<trees.length;k++)
  {
    var TempStr = "";
    if(trees[k].ParentID == OrgID)   //当前组织的ID
    {
      TempStr = TempStr + trees[k].ID + ",";
      GetNextOrgID(trees[k].ID);
      GNextOrgID = GNextOrgID + TempStr ;
    }
  }
}

//去掉重复的数据
function DelRepeatData(sData)
{
   ClearItem();
   var ary = sData.split(',');
   var iary = ary.length;
   for(i=0;i<ary.length;i++)
   {
       var itype = 0;
       for (j=i+1;j<ary.length;j++)
       {
          if(ary[i] ==ary[j])
          {
            itype =1;
            break;
          }
       }
       if(itype == 0 && i!= iary-1)
       {
         GNextOrgID = GNextOrgID + ary[i] + ",";
       }
       else
       {
         itype =0;
       }
   }   
   GetPersIDCol(GNextOrgID);                       //获取人员ID集合
}

//展开收缩下一级部门
function SpreadNextOrgTree(DeptID,ChildNum,PersNum)
{
  var i,j,k,img_src1,img_src2;
  if(ChildNum!="0" || PersNum!="0")
  {
    if(eval("document.all.T"+DeptID+".style.display")=='none')
    {
      eval("document.all.T"+DeptID+".style.display=''");    //展开下级层
      eval("document.all.img_"+DeptID+".src=\"img/sys/open.gif\";");    //展开下级层
      eval("document.all.img_"+DeptID+".lowsrc=\"img/sys/close.gif\";");    //展开下级层
    }
    else
    {
      eval("document.all.T"+DeptID+".style.display='none'");    //收缩下级层
      eval("document.all.img_"+DeptID+".src=\"img/sys/close.gif\";");    //收缩下级层
      eval("document.all.img_"+DeptID+".lowsrc=\"img/sys/open.gif\";");    //收缩下级层
    }
  }
  else
  {
  }
}

function GetSuperOrgID(OrgID)   //取得上级部门ID的集合.为展开树做准备的.
{
  var k;
  for(k=0;k<trees.length;k++)
  {
    var TempStr = "";
    if(trees[k].ID == OrgID)   //当前组织的ID
    {
      TempStr = TempStr + trees[k].ID + ",";
      GetSuperOrgID(trees[k].ParentID);
      GOrgInfo = GOrgInfo + TempStr ;
    }
  }
}

//展开一个新树

function SpreadNewOrgTree()
{  
  var i,j,k,img_src1,img_src2;
      if(GOrgInfo!="")
      {
        var ary  = GOrgInfo.split(',');
        var nary = ary.length;
        for(i=0;i<nary-1;i++)
        {
          eval("document.all.T"+ary[i]+".style.display=''");
        } 
      }
      else
      {
        //alert(GOrgInfo);
      }
}

var tgs; 
var tmp_background_val; 
function tog(n,flags)
{ 
  if (tgs)
  { 
    tgs.style.background= tmp_background_val ; 
  } 
  n.style.background= '#99ccff'; 
  tmp_background_val=flags;
  tgs=n; 
} 
-->
    </script>
</head>
<body>
<% 
  Response .ExpiresAbsolute=System.DateTime.Now. AddSeconds(-1);
  Response.Expires=0;
  Response.CacheControl = "no-cache";
%>
<form id = "hidform" method="post" runat ="server">

<table align ="center" width="98%" cellpadding ="10" cellspacing ="0" >
 <tr> 
  <td><%=sPersHtml%> <%=sDeptHtml %></td>
 </tr>
</table>

 <table cellpadding ="0" style =" width :auto;" cellspacing ="0" border ="0">
   <tr>
    <td style ="width:60px;"></td>
    <td><input type="button" id="ChoicePersID" value ="确定" class="button02" onclick ="AlreadyChoicePersInfo()" /></td>
   </tr>
 </table>
 <input type="hidden" id="hOrgInfo" runat ="server" />
 <input type="hidden" id="hOrgID" runat ="server" />
 <input type="hidden" id="hOrgName" runat ="server" />
 <input type="hidden" id="hParentOrgID" runat ="server" />
 <input type="hidden" id="hChildNumber" runat ="server" />
 <input type="hidden" id="hOrgIDCol" runat ="server" />
 <input type="hidden" id="hOrgType" runat ="server" />
 <input type="hidden" id="HPageID" runat ="server"  />
 <input type="hidden" id="HPersCount" runat ="server"  />
</form>


<script language ="javascript" type ="text/javascript" >
<!-- 
//网页对话框初始化信息
  var sData         = dialogArguments;  
  var sTemp         = hidform.HPageID.value;
  var ComparePersID = eval("sData.form1.HChoiceID_"+sTemp+".value;");
  var PAry = ComparePersID.split(',');
  var iPAry = PAry.length;
  var iPersCount = GPersCount*1;   //得到人员数;
  for(p=0;p<iPAry;p++)
  {
    var PTemp = PAry[p];
    if(iPersCount == 1)
    {
        var PersValue = document.all.PersCK.value;
        var PersAry = PersValue.split(',');
        if(PersAry[0] == PTemp)
        {
           ClearItem();
           GetSuperOrgID(PersAry[2]); //得到当前组织的上组组织的集合
           SpreadNewOrgTree();   //展开被选择的层
           document.all.PersCK.checked = true;
           break;
        }
     }
     else if(iPersCount>1)
     {
        for(j=0;j<iPersCount;j++)
        {
          var PersValue = document.all.PersCK[j].value;
          var PersAry = PersValue.split(',');
          if(PersAry[0] == PTemp)
          {
             ClearItem();
             GetSuperOrgID(PersAry[2]);
             SpreadNewOrgTree();
             document.all.PersCK[j].checked = true;
             break;
          }
       }
     }
  }
  
 //根据部门ID,得到相应的人员ID集合
 var sGetPersIDCol = "";    //得到人员ID集合
 function GetPersIDCol(OrgIDCol)
 {
   var GetOrgIDCol = OrgIDCol; // hidform.hOrgIDCol.value; //得到部门ID集合
   var ary = GetOrgIDCol.split(',');
   var iary = ary.length;
   for(i=0;i<ary.length;i++)
   {
     var x;
     for(x=0;x<Perstrees.length;x++)
     {
       if(Perstrees[x].OrgID ==ary[i])
       {
         sGetPersIDCol = sGetPersIDCol +Perstrees[x].ID + ",";
       }
     }
   }
 }
 //是否选择
 function IFChoice(obj)
 {
    if(obj.checked)
    {
       AllChoice(sGetPersIDCol);
    }
    else
    {
       DelAllChoice(sGetPersIDCol);
    }
 }
 
 //全部选择已选定当前部门及其下级人员
 function AllChoice(PersIDCol)
 {
   var i,x;
   var ary = PersIDCol.split(',');
   var iary = ary.length;
   for(i = 0;i<iary-1;i++)
   {
     if(Perstrees.length == 1)
     {
         var PersValue = document.all.PersCK.value;
         var PersAry = PersValue.split(',');
         if(PersAry[0] == ary[i])
         {
           document.all.PersCK.checked = true;
           break;
         }
      }
      else
      {
        for(x=0;x<Perstrees.length;x++)
        {
          var PersValue = document.all.PersCK[x].value;
          var PersAry = PersValue.split(',');
          if(PersAry[0] == ary[i])
          {       
            document.all.PersCK[x].checked = true;
            break;
          }
        }
      }
    }
 }
 
 //全部取消已选定当前部门及其下级人员
 function DelAllChoice(PersIDCol)
 {
   var i,x;
   var ary = PersIDCol.split(',');
   var iary = ary.length;
   for(i = 0;i<iary-1;i++)
   {
     if(Perstrees.length == 1)
     {
         var PersValue = document.all.PersCK.value;
         var PersAry = PersValue.split(',');
         if(PersAry[0] == ary[i])
         {
           document.all.PersCK.checked = false;
           break;
         }
      }
      else
      {
        for(x=0;x<Perstrees.length;x++)
        {
          var PersValue = document.all.PersCK[x].value;
          var PersAry = PersValue.split(',');
          if(PersAry[0] == ary[i])
          {
            document.all.PersCK[x].checked = false;
            break;
          }
        }
      }
    }
 }
 
 var ColseStatus = "0";
 //确定事件;
 function AlreadyChoicePersInfo()
 {
   var x;
   var ChoiceNameInfo = "";  //名称
   var ChoiceIDInfo   = "";  //ID
   //var ChoiceOrgIDInfo   = "";  //ID
   var iPersCount = GPersCount*1;
   if(iPersCount == 1)
   {
     if(document.all.PersCK.checked == true)
     {
         var PerAry      = document.all.PersCK.value.split(',') ;
         ChoiceIDInfo    = PerAry[0];
         ChoiceNameInfo  = PerAry[1];
         //ChoiceOrgIDInfo = PerAry[2];
     }
   }
   else if(iPersCount>1)
   {
     for(x=0;x<iPersCount;x++)
     {
       if(document.all.PersCK[x].checked == true)
       {
           if(ChoiceIDInfo !="")
           {
               ChoiceIDInfo    = ChoiceIDInfo    + ",";
               ChoiceNameInfo  = ChoiceNameInfo  + ",";
               //ChoiceOrgIDInfo = ChoiceOrgIDInfo + ",";
           }
           var PerAry      = document.all.PersCK[x].value.split(',') ;
           ChoiceIDInfo    = ChoiceIDInfo   + PerAry[0];
           ChoiceNameInfo  = ChoiceNameInfo + PerAry[1];
           //ChoiceOrgIDInfo = ChoiceOrgIDInfo + PerAry[2];
       }
     }
   }
      var obj         = dialogArguments;
      var sChoiceID   = hidform.HPageID.value;
      //得到第几个限定的数undefined
      var iChoiceNum  = eval("obj.iChoicePoNumber"+sChoiceID);
      if(isNaN(iChoiceNum))
	  {
	      alert("操作错误,重新进入组织树");
          return;
	  }
      if( iChoiceNum != "0")
      {
         var PersNum = ChoiceIDInfo.split(','); 
         var iPersNum = PersNum.length;
         if(iPersNum > iChoiceNum)
         {
            alert("您选择的信息已超过"+iChoiceNum+"个");
            return;
         }
      }
      obj.sChoiceID       = sChoiceID;
      obj.ChoiceNameInfo  = "\""+ ChoiceNameInfo +"\"";
      obj.ChoiceIDInfo    = "\""+ChoiceIDInfo +"\"";
      window.returnValue  = obj;
      window.close(); 
  }   
 -->
</script>        
</body>
</html>